package com.tb.ClassSchedule;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import java.util.HashSet;

/**
 * Created by 汪贵春 on 2016/7/22.
 */
public class LessonSet extends HashSet<Lesson>{

    public static int dayCount = 7;
    public static int sectionCount = 11;

    private LessonDatabaseHelper dbHelper;
    
    
    public LessonSet() {
        dbHelper = new LessonDatabaseHelper(MainActivity.main, "Lessons.db", null, 1);
        SQLiteDatabase db = dbHelper.getWritableDatabase();

        Log.d("database","start");

        Cursor cursor = db.query("Lesson",null,null,null,null,null,null);
        if(cursor.moveToFirst()){
            do{
                String className = cursor.getString(cursor.getColumnIndex("ClassName"));
                int weekDay = cursor.getInt(cursor.getColumnIndex("WeekDay"));
                int startSection = cursor.getInt(cursor.getColumnIndex("StartSection"));
                int endSection = cursor.getInt(cursor.getColumnIndex("EndSection"));
                int startWeek = cursor.getInt(cursor.getColumnIndex("StartWeek"));
                int endWeek = cursor.getInt(cursor.getColumnIndex("EndWeek"));
                String teacherName = cursor.getString(cursor.getColumnIndex("TeacherName"));
                String address = cursor.getString(cursor.getColumnIndex("Address"));

                Log.d("database",className + " | " + weekDay + " | " + startSection + " | " + endSection + " | " + startWeek + " | " + endWeek + " | " + teacherName + " | " + address);

                add(new Lesson(className,weekDay,startSection,endSection,startWeek,endWeek,teacherName,address));

            }while (cursor.moveToNext());
        }
        cursor.close();

    }


}
